package aad.storyboard.controller;

import java.util.Observable;
import java.util.Observer;


/**
 * Observer pattern: observes the AudioPlayer and updates its currentTime according to the current position of the AudioPlayer 
 */
public class StoryTimer extends Observable implements Observer, Runnable{
	
    private int currentTime = 0;
    private long currentSystemTime=0;
    private boolean playing;
    
    /**
     * Singleton
     */
    private static StoryTimer inst = new StoryTimer ();

	private StoryTimer(){}
	
	
	/**
	 * Singleton
	 * @return
	 */
	public static StoryTimer getInstance(){
		return inst;
	}    
    
    public int getCurrentTime() {
        return currentTime;
    }//getCurrentTime
    
    	
    /**
     * notifies its observers in order to start story components when their start time has been reached
     */
    @Override
	public void update(Observable arg0, Object arg1) {
		currentTime=((AudioPlayer)arg0).getCurrentPosition();
		currentSystemTime=System.currentTimeMillis();
		setChanged();
		notifyObservers();
				
	}

	@Override
	public void run() {
		new Thread(this).start();
		
	}
}

